package com.foundryx.shared.exception.message;

import com.foundryx.shared.core.utils.StringUtil;
import com.foundryx.shared.exception.i18n.I18nMessageUtil;

import java.util.Locale;

/**
 * @className: PropertiesBasedMessageResolver
 * @author: ocxz1
 * @date: 2025/6/20 下午1:45
 * @Version: 1.0
 * @description: fx-share-resources
 */
public class PropertiesBasedMessageResolver implements MessageResolver {

    private final String baseName;

    public PropertiesBasedMessageResolver(String baseName) {
        this.baseName = baseName;
    }

    @Override
    public String resolveMessage(String msgCode, Object[] args, Locale locale) {
        if (msgCode == null) {
            return null;
        }
        String rawMsg = I18nMessageUtil.getMessage(baseName, msgCode, locale);
        if (args == null || args.length == 0) {
            return rawMsg;
        }
        return StringUtil.format(rawMsg, args);
    }
}
